<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Pragma" content="no-cache">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
    <meta name="format-detection" content="telephone=no" />
    <title>我的资料</title>
    <meta content="" name="keywords" />
    <meta content="" name="description" />
    <meta content="" name="copyright" />
    <meta content="" name="author" />
    <meta name="robots" content="noarchive">
    <meta name="robots" content="noarchive">
    <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
    <script src="https://webapi.amap.com/maps?v=1.4.14&key=a451001d808ffff80790d52df188b739"></script>
    <script src="layer/layer.js"></script>
    <script type="text/javascript" src="js/map.js"></script>
    <script src="js/urlTool.js"></script>
    <link rel="stylesheet" href="css/public.css" />
    <link rel="stylesheet" href="css/style.css">
</head>

<body>
    <!--头部-->
    <div class="return_top bgyellow">
        <a href="unionCenter.html">
            <span class="login_home cfff">返回</span>
        </a>
    </div>
    <!--//头部结束-->
    <!--主体区域-->
    <div class="bgfff cb7 pl20 pr20">
        <p class="tc fz30 pt50 cblue">完善资料</p>
        <form action="" method="post">
            <input type="hidden" id="shopId">
            <div class="mydata_inf bb mt20">
                <img src="temp/datacenter.png" class="mydata_inf_img mr20">
                <input placeholder="单位名称" id="shopName" value="" keyboardtype="web-search" type="search" class="mydata_inf_input mr20 fz28">
            </div>
            <div class="mydata_inf bb mt20">
                <img src="temp/datacenter.png" class="mydata_inf_img mr20">
                <input placeholder="单位全称" id="shopFullname" value="" keyboardtype="web-search" type="search" class="mydata_inf_input mr20 fz28">
            </div>
            <div class="mydata_inf bb mt20">
                <img src="temp/addr.png" class="mydata_inf_img mr20">
                <input placeholder="详细地址" id="shopAddr" value="" keyboardtype="web-search" type="search" class="mydata_inf_input mr20 fz28">
                <input type="hidden" id="shopArea">
            </div>
            <div class="mydata_inf bb">
                <img src="temp/datags.png" class="mydata_inf_img mr20">
                <input placeholder="联系人" id="shopContract" value="" keyboardtype="web-search" type="search" class="mydata_inf_input mr20 fz28">
            </div>
            <div class="mydata_inf bb" id="mydata_phone">
                <img src="temp/datacall.png" class="mydata_inf_img mr20">
                <input placeholder="手机号" value="" keyboardtype="web-search" type="number" class="mydata_inf_input mr20 fz28" id="phone">
            </div>
            <p class="cred tc pt10 hide tishi">请输入手机号</p>
            <p class="cred tc pt10 hide tishitext">手机或电话号码格式不正确。</p>

            <div class="union_Code bb clear">
                <div class="fl union_Code_fl">
                    <img src="temp/yzmu.png" class="union_Code_img fl mt25">
                    <input placeholder="请输入手机验证码" id="vcode" value="" keyboardtype="web-search" type="number" maxlength="6" class="union_Code_input fr fz28">
                </div>
                <input type="button" class="fr c999 carmasterbutton union_Code_fr fz26" value="点击发送验证码" onclick="sendCode(this)" />
            </div>

            <div class="car_cont">
                <button type="button" class="w100 car_cont_submit fz32 cfff" id="save_btn">保存</button>
            </div>
        </form>
    </div>

<!--底部-->
<div class="footerpage"></div>
<!--//底部-->
</body>

<script type="text/javascript">
$(".footerpage").load("footer.html",'',function() {    
    $('#myCenter').addClass("select-two").children().attr("class","myCenterclick");
});
    let type = 'save';
    sm.req({
        url: '/sysShop/myShopMsg',
        done: function(res) {
            if (res.code == 200) {
                if (JSON.stringify(res.data) === '{}' || res.data == null || res.data == undefined || res.data == '') {
                    type = 'reg';
                } else {
                    $("#shopId").val(res.data.shopId);
                    $("#shopName").val(res.data.shopName);
                    $("#shopFullname").val(res.data.shopFullname);
                    $("#shopArea").val(res.data.shopArea);
                    $("#phone").val(res.data.shopPhone);
                    $("#shopContract").val(res.data.shopContract);
                    $("#shopAddr").val(res.data.shopAddr);
                }
            } else {
                layer.open({
                    content: res.message,
                    btn: '我知道了'
                });
            }
        }
    });
    var clock = '';
    var nums = 10;
    var btn;

    function sendCode(thisBtn) {
        btn = thisBtn;
        let isPhone = union_check();
        if (isPhone == false) {
            return false;
        }
        sm.req({
            url: '/common/sendCode',
            dataType: 'json',
            type: 'post',
            data: {
                phone: $("#phone").val()
            },
            done: function(res) {
                if (res.code == 200) {
                    btn.disabled = true; //将按钮置为不可点击
                    btn.value = nums + '秒后可重新获取';
                    clock = setInterval(doLoop, 1000); //一秒执行一次
                } else {
                    layer.open({
                        content: res.message,
                        btn: '我知道了'
                    });
                }
            }
        });
    }

    function doLoop() {
        nums--;
        if (nums > 0) {
            btn.value = nums + '秒后可重新获取';
        } else {
            clearInterval(clock); //清除js定时器
            btn.disabled = false;
            btn.value = '点击发送验证码';
            nums = 10; //重置时间
        }
    }
    AMap.plugin('AMap.Autocomplete', function() {
        // 实例化Autocomplete
        var autoOptions = {
            input: 'shopAddr'
        }
        var autoComplete = new AMap.Autocomplete(autoOptions);
        autoComplete.on('select', function(res) {
            $("#shopArea").val(res.poi.adcode);
        })
    })
    $("#save_btn").on('click', function() {
        let that = $(this);
        if (that.is(':disabled')) {
            return false;
        }
        let shopId = $("#shopId").val();
        let shopName = $("#shopName").val();
        let shopFullName = $("#shopFullname").val();
        let shopAddr = $("#shopAddr").val();
        let shopContract = $("#shopContract").val();
        let shopArea = $("#shopArea").val();
        let shopPhone = $("#phone").val();
        let vcode = $("#vcode").val();
        if ($.trim(shopName) == '') {
            layer.open({
                content: '请填写单位名称！',
                btn: '我知道了'
            });
            $("#shopName").parent().removeClass('bb').addClass('bred').siblings().removeClass('bred').addClass('bb');
            return false;
        }
        if ($.trim(shopFullName) == '') {
            layer.open({
                content: '请填写单位全称！',
                btn: '我知道了'
            });
            $("#shopFullName").parent().removeClass('bb').addClass('bred').siblings().removeClass('bred').addClass('bb');
            return false;
        }
        if ($.trim($("#shopAddr").val()) == '') {
            layer.open({
                content: '请填写详细地址！',
                btn: '我知道了'
            });
            $("#shopAddr").val().parent().removeClass('bb').addClass('bred').siblings().removeClass('bred').addClass('bb');
            return false;
        }
        if ($.trim(shopContract) == '') {
            layer.open({
                content: '请填写联系人！',
                btn: '我知道了'
            });
            $("#shopContract").parent().removeClass('bb').addClass('bred').siblings().removeClass('bred').addClass('bb');
            return false;
        }
        if ($.trim(shopPhone) == '') {
            layer.open({
                content: '请填写手机号！',
                btn: '我知道了'
            });
            $("#phone").parent().removeClass('bb').addClass('bred').siblings().removeClass('bred').addClass('bb');
            return false;
        }
        if (!(/^1[3456789]\d{9}$/.test(shopPhone))) {
            layer.open({
                content: '手机号码有误！',
                btn: '我知道了'
            });
            $("#phone").parent().removeClass('bb').addClass('bred').siblings().removeClass('bred').addClass('bb');
            return false;
        }
        if ($.trim(vcode) == '') {
            layer.open({
                content: '请填写验证码！',
                btn: '我知道了'
            });
            $("#vcode").parent().parent().removeClass('bb').addClass('bred').siblings().removeClass('bred').addClass('bb');
            return false;
        }
        let regData = {
            shopName: shopName,
            shopFullname: shopFullName,
            shopArea: shopArea,
            shopAddr: shopAddr,
            shopPhone: shopPhone,
            shopContract: shopContract,
            vcode: vcode,
            shopType: 0
        }
        if (shopId != "") {
            regData.shopId = shopId;
        }
        let posturl = '/sysShop/update';
        if (type == 'reg') {
            posturl = '/sysShop/register';
        }
        sm.req({
            url: posturl,
            data: regData,
            done: function(res) {
                if (res.code == 200) {
                    layer.open({
                        content: '保存成功',
                        btn: '我知道了',
                        yes: function(index) {
                            layer.close(index)
                            location.href = "unionCenter.html";
                        }
                    });
                } else {
                    layer.open({
                        content: res.message,
                        btn: '我知道了'
                    });
                }
            }
        });
    });
</script>

</html>